package com.example.notice_management_p1.controller;
import com.example.notice_management_p1.service.INoticeService;
import com.pojo.Entity.Notice;
import com.pojo.dto.ToNotice;
import com.pojo.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RequestMapping("notice")
@RestController
public class NoticeController {
    @Autowired
    INoticeService iNoticeService;
    @GetMapping("/getlnotice/{page}/{number}")
    public Result<?> getlnotice(@PathVariable Integer page, @PathVariable Integer number,HttpServletRequest httpServletRequest){
        List<ToNotice> list=iNoticeService.getlnotice(page,number);
        Result result=Result.success(list);
        result.setMessage(String.valueOf(iNoticeService.getsum()));
        return result;
    }
    @GetMapping("/getnotice/{nID}")
    public Result<?>getnotice(@PathVariable Integer nID){
        return Result.success(iNoticeService.getnotice(nID));
    }
    @PostMapping("/update")
    public Result<?>updatenotice( Notice notice, HttpServletRequest httpServletRequest){
        return iNoticeService.update(notice,httpServletRequest)==1?Result.success(1):Result.failure();
    }
    @PostMapping("/insert")
    public Result<?>uinsertnotice( Notice notice, HttpServletRequest httpServletRequest){
        System.out.println(httpServletRequest.getHeader("insert"));
        return iNoticeService.insert(notice,httpServletRequest)==1?Result.success(1):Result.failure();
    }
    @PostMapping("/delete")
    public Result<?>deletenotice(@RequestParam Integer nID){
        System.out.println(nID);
        return iNoticeService.delete(nID)==1?Result.success(1):Result.failure();
    }

}
